package com.cat.binaryTree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/
 * @create 2025/9/30 19:21
 * @since JDK17
 */

public class Solution94 {
    List<TreeNode> list = new ArrayList<>();
    void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        list.add(root);
        dfs(root.left);
        dfs(root.right);
    }
    public void flatten(TreeNode root) {
        dfs(root);
        for (int i = 1; i < list.size(); i++) {
            TreeNode last = list.get(i - 1), cur = list.get(i);
            last.left = null;
            last.right = cur;
        }
    }
}
